# Maintainer: Christian Rebischke <chris.rebischke@archlinux.org>

pkgname=hostess
pkgver=0.5.2
pkgrel=4
pkgdesc="An idempotent command-line utility for managing your /etc/hosts file."
url="https://github.com/cbednarski/hostess"
arch=("loong64" "x86_64")
license=('MIT')
depends=('glibc')
makedepends=("go")
source=("${pkgname}-${pkgver}.tar.gz::https://github.com/cbednarski/hostess/archive/v${pkgver}.tar.gz")
sha512sums=('47c81318cdb1c62c4112612e3e93cb3a171a8daf007e123212ba459efdf73b7dbc14871ee07e9e69af37750f2eb74c4d852c6c7c252788248698b762587638dc')
options=('!lto')

build() {
  cd "${pkgname}-${pkgver}"
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  export CGO_LDFLAGS="${LDFLAGS}"
  export GOFLAGS="-buildmode=pie -trimpath -mod=readonly -modcacherw"
  go build -ldflags "-linkmode=external" -o "${pkgname}-bin"
}

check() {
  cd "${pkgname}-${pkgver}"
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  export CGO_LDFLAGS="${LDFLAGS}"
  go test -v
}

package() {
  cd "${pkgname}-${pkgver}"
  install -Dm755 "${pkgname}-bin" "${pkgdir}/usr/bin/${pkgname}"
}
